﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using PowerCreator.LMS.DL.Project.Entity;
using PowerCreator.LMS.Web.DL.Project;
using PowerCreator.LMS.Common.Script;
public partial class sysadmin_DL_Project_ManageClassMember : PowerCreator.LMS.Web.Base.WebBasePage
{
    TOClass objClass = new TOClass();
    TOUserOfClass objUserOfClass = new TOUserOfClass();
    PowerCreator.LMS.ViewQuery.ViewQuery obj = new PowerCreator.LMS.ViewQuery.ViewQuery();
    private PowerCreator.LMS.Web.DL.User.LoginEntity login = new PowerCreator.LMS.Web.DL.User.LoginEntity();
    private string url = "../../login.aspx";
  
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUser();
        if (!IsPostBack)
        {
            InitPage();
            int CID = 0;
            if (Request.QueryString["CID"] != null)
            {
                CID = int.Parse(Request.QueryString["CID"].ToString());
                ViewState["CID"] = CID.ToString();
                VOTOClass voclass = objClass.Load(CID);
                ViewState["CourseListID"] = voclass.ClassCourseListID.ToString();

                BinderDt();
            }
            if (CheckPopedom() == 5)
            {
                td_ClassUser.Visible = false;
                td_ManageClassNotice.Visible = false;
            }
        }
    }

    private void CheckUser()
    {
        if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
        {
            Script.RedirectNewUrl(url);
        }
        else
        {
            login = (PowerCreator.LMS.Web.DL.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
            if (login == null)
            {
                Script.RedirectNewUrl(url);
            }
            else
            {
                if (login.VOAdvancedUser == null)
                {
                    Script.RedirectNewUrl(url);
                }
                else if (login.VOAdvancedUser.AUserGroup > 5)
                {
                    //Response.Write(login.VOAdvancedUser.AUserGroup.ToString());
                    //Response.End();
                    Script.ShowAndHistory("您无此权限！", -1);
                }
            }
        }


    }
    private int CheckPopedom()
    {
        int rt = 0;

        login = (PowerCreator.LMS.Web.DL.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
        if (login != null)
        {
            rt = login.VOAdvancedUser.AUserGroup;
        }
        return rt;

    }
    protected override void InitPage()
    {
        
        base.InitPage();


    }



    private void BinderDt()
    {
        VOTOAdvancedUser vo = new VOTOAdvancedUser();
        TOAdvancedUser objAdvancedUser = new TOAdvancedUser();

        string search = "SELECT TO_Class.Class_Id, TO_Class.Name,  TO_CourseList.CourseListName, TO_Class.Broswer, TO_Class.ClassAssistant, TO_Class.ClassLeader,  TO_Class.ClassLecturer FROM TO_Class ,TO_CourseList Where TO_Class.ClassCourseListID = TO_CourseList.CourseList_Id";
        if (ViewState["CID"] != null)
        {
            search += " and TO_Class.Class_Id=" + ViewState["CID"].ToString();
        }
        DataTable dt = obj.Query(search);
        dt.Columns.Add("ClassAssistantName");
        dt.Columns.Add("ClassLeaderName");
        dt.Columns.Add("ClassLecturerName");
        dt.Columns.Add("StrState");
        dt.Columns.Add("ClassUserNum");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            //vo = objAdvancedUser.Load(int.Parse(dt.Rows[i]["ClassAssistant"].ToString()));
            //dt.Rows[i]["ClassAssistantName"] = vo.Name;
            //vo = objAdvancedUser.Load(int.Parse(dt.Rows[i]["ClassLeader"].ToString()));
            //dt.Rows[i]["ClassLeaderName"] = vo.Name;
            //vo = objAdvancedUser.Load(int.Parse(dt.Rows[i]["ClassLecturer"].ToString()));
            //dt.Rows[i]["ClassLecturerName"] = vo.Name;

            if (dt.Rows[i]["Broswer"].ToString() == "True")
                dt.Rows[i]["StrState"] = "允许";
            else
                dt.Rows[i]["StrState"] = "不允许";

            dt.Rows[i]["ClassUserNum"] = objUserOfClass.Count("ClassID=" + ViewState["CID"].ToString() + "");
        }
        rptNew.DataSource = dt;
        rptNew.DataBind();

    }



    protected void btnAddUser_Click(object sender, EventArgs e)
    {
        string url = "AddClass.aspx";
        Script.RedirectURL(url);

    }




    protected void btnManageUser_Click(object sender, EventArgs e)
    {
       
    }
    protected void btn_ManageClassTask_Click(object sender, EventArgs e)
    {

    }
    protected void btn_ManageClassExam_Click(object sender, EventArgs e)
    {

    }
 
}


